package com.zmm.zebulon.starter.protection.idempotent.config;

import com.zmm.zebulon.starter.protection.idempotent.core.aop.IdempotentAspect;
import com.zmm.zebulon.starter.protection.idempotent.core.keyresolver.IdempotentKeyResolver;
import com.zmm.zebulon.starter.protection.idempotent.core.keyresolver.impl.DefaultIdempotentKeyResolver;
import com.zmm.zebulon.starter.protection.idempotent.core.keyresolver.impl.ExpressionIdempotentKeyResolver;
import com.zmm.zebulon.starter.protection.idempotent.core.redis.IdempotentRedisDao;
import com.zmm.zebulon.starter.redis.config.ZebulonRedisAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.List;

/**
 * description: TODO
 *
 * @author zebulon
 * package com.zmm.zebulon.starter.protection.idempotent.config
 * name: ZebulonIdempotentConfiguration
 * date 2024/1/7 15:31
 */
@AutoConfiguration(after = ZebulonRedisAutoConfiguration.class)
public class ZebulonIdempotentConfiguration {

    @Bean
    public IdempotentAspect idempotentAspect(List<IdempotentKeyResolver> keyResolvers, IdempotentRedisDao idempotentRedisDAO) {
        return new IdempotentAspect(keyResolvers, idempotentRedisDAO);
    }

    @Bean
    public IdempotentRedisDao idempotentRedisDAO(StringRedisTemplate stringRedisTemplate) {
        return new IdempotentRedisDao(stringRedisTemplate);
    }

    // ========== 各种 IdempotentKeyResolver Bean ==========

    @Bean
    public DefaultIdempotentKeyResolver defaultIdempotentKeyResolver() {
        return new DefaultIdempotentKeyResolver();
    }

    @Bean
    public ExpressionIdempotentKeyResolver expressionIdempotentKeyResolver() {
        return new ExpressionIdempotentKeyResolver();
    }

}

